const express = require('express')
const mutil = require('connect-multiparty')

const app = express()

app.use(function (req, res, next) {
  res.set('Access-Control-Allow-Origin', '*')
  next()
})

// 处理post请求,url编码数据
app.use(express.urlencoded({ extended: false }))
// 处理post请求.formdata编码数据
app.use(mutil())

app.get('/test', (req, res) => {
  console.log(req.body)
  setTimeout(() => {
    res.send([1, 2, 3])
  }, 2000)
})
app.post('/test', (req, res) => {
  const { username, password, xxx } = req.body
  res.send({ username, password, xxx })
})

app.listen(5000, (error) => {
  if (error) console.log('fail')
  else console.log('ok')
})
